package com.star.cat.common.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class DateUtil {
	
	public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
	
	public static String toLocalDateTime(Instant time){
		LocalDateTime localDateTime = LocalDateTime.ofInstant(time, ZoneId.systemDefault());
		return localDateTime.format(formatter);
	}
	
	public static Instant toInstant(String time){
		LocalDateTime localDateTime = LocalDateTime.parse(time,formatter);
		return localDateTime.atZone(ZoneId.systemDefault()).toInstant();
	}

	public static void main(String[] args) {
		String time= "2019-07-20 10:37:07";
		LocalDateTime localDateTime = LocalDateTime.parse(time,formatter);
		localDateTime.atZone(ZoneId.systemDefault()).toInstant();
	}
	
}
